$(function(){
	dictionaryStart("model","143001");
	dictionaryStart("productionfactory","143002");
	$("#combinationdevicetype").bind('change',function(){
		zhsbChange();
	});
});
function zhsbChange(){
	var type=$("#combinationdevicetype").val();
	if(type=="否"){
		$("input[name='combinationdevicename']").val("");
		$("input[name='combinationdevicename']").attr("readonly","readonly");
	}else{
		$("input[name='combinationdevicename']").removeAttr("readonly");
	}
}

function add(){
	var devicename=$("#devicename").val();
	if(devicename==""){
		alert('设备名称为空');
		$("#devicename").focus();
		return;
	}
	/*if($("input[name='localcity']").val()==""){
		alert("所属地市为空");
		$("input[name='localcity']").focus();
		return;
	}
	if($("input[name='operationunit']").val()==""){
		alert("运维单位为空");
		$("input[name='operationunit']").focus();
		return;
	}
	if($("input[name='maintenanceteam']").val()==""){
		alert("维护单位为空");
		$("input[name='maintenanceteam']").focus();
		return;
	}
	if($("input[name='gapcode']").val()==""){
		alert("间隔单元为空");
		$("input[name='gapcode']").focus();
		return;
	}
	if($("input[name='commissioningdate']").val()==""){
		alert("投运日期为空");
//		$("input[name='commissioningdate']").focus();
		return;
	}
	if($("input[name='equipmentowner']").val()==""){
		alert("设备主人为空");
		$("input[name='equipmentowner']").focus();
		return;
	}
	if($("input[name='interphasevalue']").val()!=""&&!isInt($("input[name='interphasevalue']").val())){
		alert("相间动作定值必须为数字");
		$("input[name='workingvoltage']").focus();
		return;
	}
	if(!isNum($("input[name='shortcircuitstartcurrent']").val())){
		alert("短路启动电流必须为小数");
		$("input[name='shortcircuitstartcurrent']").focus();
		return;
	}
	if(!isNum($("input[name='groundingstartcurrent']").val())){
		alert("接地启动电流必须为小数");
		$("input[name='groundingstartcurrent']").focus();
		return;
	}
	if($("input[name='assetnumber']").val()==""){
		alert("资产编号为空");
		$("input[name='assetnumber']").focus();
		return;
	}*/
	var list=$("#form").serialize();
	$.ajax({
		url : contextPath+"user/zyzngzzsq/add",
		data : {data : list},
		type : "post",
		success : function(data){
			alert(data.msgDesc);
			if(data.opResult=="0"){
				location.href=contextPath+"user/z/zyzngzzsqlist.jsp?deviceid="+deviceid+"&devicetype="+devicetype+"&t="+new Date().getTime();
			}
		}
	});
}

function edite(){
	var devicename=$("#devicename").val();
	if(devicename==""){
		alert('设备名称为空');
		$("#devicename").focus();
		return;
	}
	/*if($("input[name='localcity']").val()==""){
		alert("所属地市为空");
		$("input[name='localcity']").focus();
		return;
	}
	if($("input[name='operationunit']").val()==""){
		alert("运维单位为空");
		$("input[name='operationunit']").focus();
		return;
	}
	if($("input[name='maintenanceteam']").val()==""){
		alert("维护单位为空");
		$("input[name='maintenanceteam']").focus();
		return;
	}
	if($("input[name='gapcode']").val()==""){
		alert("间隔单元为空");
		$("input[name='gapcode']").focus();
		return;
	}
	if($("input[name='commissioningdate']").val()==""){
		alert("投运日期为空");
//		$("input[name='commissioningdate']").focus();
		return;
	}
	if($("input[name='equipmentowner']").val()==""){
		alert("设备主人为空");
		$("input[name='equipmentowner']").focus();
		return;
	}
	if($("input[name='interphasevalue']").val()!=""&&!isInt($("input[name='interphasevalue']").val())){
		alert("相间动作定值必须为数字");
		$("input[name='workingvoltage']").focus();
		return;
	}
	if(!isNum($("input[name='shortcircuitstartcurrent']").val())){
		alert("短路启动电流必须为小数");
		$("input[name='shortcircuitstartcurrent']").focus();
		return;
	}
	if(!isNum($("input[name='groundingstartcurrent']").val())){
		alert("接地启动电流必须为小数");
		$("input[name='groundingstartcurrent']").focus();
		return;
	}
	if($("input[name='assetnumber']").val()==""){
		alert("资产编号为空");
		$("input[name='assetnumber']").focus();
		return;
	}*/
	var list=$("#form").serialize();
	$.ajax({
		url : contextPath+"user/zyzngzzsq/edite",
		data : {data : list},
		type : "post",
		success : function(data){
			alert(data.msgDesc);
			if(data.opResult=="0"){
				location.href=contextPath+"user/z/zyzngzzsqlist.jsp?deviceid="+deviceid+"&devicetype="+devicetype+"&t="+new Date().getTime();
			}
		}
	});
}

function setDefault(elementId,data){
	$('#'+elementId).val(data);
}